<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        function Vue({data}){
            this._data = data

            for (let key in this._data){
                Object.defineProperty(this._data,key,{
                    get(){
                        return this._data
                    },
                    set(v) {
                        this._data = v
                    }
                })
            }
            observer(data)
        }
        function observer(data){
            if(typeof data !== "object" || data === null) return;
            for (let key in data){
                defineProperty(data,key)
            }
        }

        function defineProperty(data,key){
            let value = data[key]
            //更深层次的劫持
            observer(value)
            Object.defineProperty(data,key,{
                get(){
                    return value
                },
                set(v) {
                    value = v
                }
            })
        }
        const vm = new Vue({
            data:{
                count:1,
                price:299,
                user:{
                    name:"lisi",
                    age:12
                },
                course:["html","css","js"]
            }
        })
    </script>
</body>
</html>